home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroTCL3.0 folder / TCL / NeoDemo / Source / CNeoPopupPane.cp < prev    next >
Encoding:
Text File  |  1994-01-14  |  6.3 KB  |  229 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CNeoPopupPane.c
  3.  
  4.         A subclass of CStdPopupMenu that support multiple font sizes.
  5.  
  6.     SUPERCLASS = CStdPopupMenuPane
  7.  
  8.     Copyright © 1992 NeoLogic Systems. All rights reserved.
  9.  
  10.  
  11.  ******************************************************************************/
  12.  
  13. #include "NeoTypes.h"
  14. #include "CBartender.h"
  15. #include "CPaneBorder.h"
  16. #include "CPopupMenu.h"
  17. #include "CNeoPopupPane.h"
  18. #include "CNeoDemoDoc.h"
  19. #include "CNeoDLOGDialog.h"
  20.  
  21. #define SysFontFam  ((short*) 0x0BA6)
  22. #define SysFontSize ((short*) 0x0BA8)
  23. #define LastSpExtra ((long*)  0x0B4C)
  24.  
  25. extern CBartender    *gBartender;
  26.  
  27. /******************************************************************************
  28.  CNeoPopupPane
  29.  
  30.      Create a standard popup menu pane. The constant kAutoSize may be passed
  31.      for both aWidth and aHeight to request that the popup dimensions
  32.      be calculated to the best size.
  33. ******************************************************************************/
  34.  
  35. void CNeoPopupPane::INeoPopupPane(short menuID, CView *anEnclosure,
  36.             CBureaucrat *aSupervisor, short aWidth, short aHeight,
  37.             short aHEncl, short aVEncl, short aTitleGap)
  38. {
  39.     fTitleGap = aTitleGap;
  40.     fCurrentItem = 1;
  41.     IStdPopupPane(menuID, anEnclosure, aSupervisor, aWidth, aHeight, aHEncl, aVEncl);
  42. }    /* CNeoPopupPane::INeoPopupPane */
  43.  
  44. /******************************************************************************
  45.  CalcDimensions
  46.  
  47.      Calculate dimensions and location constants needed to properly draw the
  48.      popup.
  49. ******************************************************************************/
  50.  
  51. void CNeoPopupPane::CalcDimensions()
  52. {
  53.     short        newWidth, newHeight;
  54.     Rect        deltaSize;
  55.     Str255        title;
  56.     FontInfo    fInfo;
  57.  
  58.     Prepare();
  59.     itsMenu->GetTitle(title);
  60.     titleWidth = StringWidth(title);
  61.     GetFontInfo(&fInfo);
  62.  
  63.         /* fontAscent is used when drawing the popup title and selected item */
  64.     fontAscent = fInfo.ascent +1;
  65.  
  66.     if (width == kAutoSize)
  67.     {
  68.         /* calculte width such that title, the longest menu item, and        */
  69.         /* the down arrow all fit correctly                                    */
  70.  
  71.         newWidth = titleWidth + fTitleGap + itsMenu->GetWidth(); /* TCL 1.1.1 DLP 9/18/91 */
  72.     }
  73.     else newWidth = width;
  74.  
  75.     if (height == kAutoSize)
  76.     {
  77.         /* calculate the height given the chosen font, but make sure        */
  78.         /* the height is at least an appropriate minimum size                */
  79.  
  80.         newHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  81.         newHeight = Max(kStdPopupHeight, newHeight);
  82.     }
  83.     else newHeight = height;
  84.  
  85.     SetRect(&deltaSize, 0, 0, newWidth - width, newHeight - height);
  86.     ChangeSize(&deltaSize, FALSE);
  87.  
  88.         /* calculate the rect to hilite when the menu pops up, as per HIG    */
  89.  
  90.     SetRect(&hiliteRect, 0, 1, titleWidth + fTitleGap,
  91.                 fInfo.ascent + fInfo.descent + fInfo.leading + 1);
  92.  
  93.         /* calculate the position to draw the down arrow SICN                */
  94.  
  95.     sicnPt.h = width - kArrowWidth - kBorderWidth - kArrowRightInset;
  96.     sicnPt.v = 4;
  97.  
  98. }    /* CNeoPopupPane::CalcDimensions */
  99.  
  100. /******************************************************************************
  101.  DoClick {OVERRIDE}
  102.  
  103.      Hancle a click in the popup. As per HIG, we only popup the menu
  104.      when the popup box is clicked, not just any part of the pane.
  105.      We also hilite the title while the menu is popped up.
  106. ******************************************************************************/
  107.  
  108. void CNeoPopupPane::DoClick( Point hitPt, short modifierKeys, long when)
  109. {
  110.     short        saveFont;
  111.     short        saveSize;
  112.     short        count;
  113.     short        index;
  114.     MenuHandle    menu;
  115.  
  116.  
  117.     saveFont = textFont;
  118.     textFont = 0;
  119.     *LastSpExtra = -1L;                    // Signal to flush font cache
  120.  
  121.     count = itsMenu->GetNumItems();
  122.     menu = itsMenu->GetMacMenu();
  123.     for (index = 1; index <= count; index++)
  124.         SetItemMark(menu, index, ((index == fCurrentItem) ? checkMark : noMark));
  125.  
  126.     inherited::DoClick(hitPt, modifierKeys, when);
  127.  
  128.     fCurrentItem = itsMenu->GetCheckedItem();
  129.     textFont = saveFont;
  130.     *LastSpExtra = -1L;                    // Signal to flush font cache
  131. }    /* CNeoPopupPane::DoClick */
  132.  
  133. /******************************************************************************
  134.  GetCheckedItem
  135.  
  136.      Return item number if any item in menu has a checkmark, else
  137.      returns 0.
  138. ******************************************************************************/
  139.  
  140. short CNeoPopupPane::GetCheckedItem(void)
  141. {
  142.     return fCurrentItem;
  143. }    /* CNeoPopupPane::GetCheckedItem */
  144.  
  145. /******************************************************************************
  146.  MakePopupBox
  147.  
  148.      Create the pane and border used to draw the popup box and drop shadow
  149. ******************************************************************************/
  150.  
  151. void CNeoPopupPane::MakePopupBox(void)
  152. {
  153.     CPaneBorder        *border;
  154.     short            bWidth;
  155.  
  156.     bWidth = width - titleWidth - fTitleGap-2;
  157.  
  158.     popupPt.h = titleWidth + fTitleGap;
  159.     popupPt.v = 1;
  160.  
  161.     itsPopupBox = new(CPane);
  162.     itsPopupBox->IPane(this, this, bWidth, height-kBorderWidth-1, popupPt.h,
  163.                     1, sizFIXEDSTICKY, sizFIXEDSTICKY);
  164.  
  165.     border = new(CPaneBorder);
  166.     border->IPaneBorder(kBorderFrame);
  167.     border->SetShadow(2, 2, 1, 1);
  168.  
  169.     itsPopupBox->SetBorder(border);
  170.  
  171. }    /* CStdPopupPane::MakePopupBox */
  172.  
  173. /******************************************************************************
  174.  ProviderChanged
  175.  
  176.      Create the pane and border used to draw the popup box and drop shadow
  177. ******************************************************************************/
  178.  
  179. void CNeoPopupPane::ProviderChanged(CCollaborator *aProvider, long aReason, void* aParam)
  180. {
  181.     switch (aReason) {
  182.     case popupMenuNewSelection:
  183.         if (aProvider == itsMenu) {
  184.             ((CNeoDemoDoc *)((CNeoDLOGDialog *)itsSupervisor)->itsSupervisor)->setImageDirty(this, aParam, TRUE);
  185.             Refresh();
  186.         }
  187.         break;
  188.     }
  189.  
  190.     inherited::ProviderChanged(aProvider, aReason, aParam);
  191. }
  192.  
  193. /******************************************************************************
  194.  SelectItem
  195.  
  196.      Applys the action requested in actionType to the item. The valid
  197.      actions are:
  198.          pmForceOn    - always check the item
  199.          pmForceOff    - always uncheck the item
  200.          pmToggle    - check if unchecked, uncheck if checked.
  201. ******************************************************************************/
  202.  
  203. void CNeoPopupPane::SelectItem(short aItem, tPMSelectAction aType)
  204. {
  205.     itsMenu->SelectItem(aItem, aType);
  206.  
  207.     switch (aType) {
  208.     case pmToggle:
  209.         if (aItem == fCurrentItem)
  210.             fCurrentItem = 0;
  211.         else
  212.             NeoAssert(FALSE);
  213.         break;
  214.  
  215.     case pmForceOn:
  216.         fCurrentItem = aItem;
  217.         break;
  218.  
  219.     case pmForceOff:
  220.         if (aItem == fCurrentItem)
  221.             NeoAssert(FALSE);
  222.         else
  223.             fCurrentItem = 0;
  224.         break;
  225.     }
  226. }    /* CNeoPopupPane::SelectItem */
  227.  
  228.  
  229.